//
//  SLSettingViewController.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/24.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "SLSettingViewController.h"
#import "SLModfiyPassCodeViewController.h"
#import "SLAboutViewController.h"

@interface SLSettingViewController ()

@end

@implementation SLSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"设置" back:YES];
    self.view.backgroundColor =RGBACOLOR(248, 248, 248, 1.0);
    UIButton *btn1 = [self actionButton:@"修改密码"];
    [btn1 addTarget:self action:@selector(modifyPassCode:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    UIButton *btn2 = [self actionButton:@"关于"];
    btn2.frame = CGRectMake(0, btn1.bottom + 15, App_Frame_Width, 44);
    [btn2 addTarget:self action:@selector(openAbout:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    UIButton *quitBtn = [[UIButton alloc]init];
    [quitBtn setTitle:@"退出" forState:UIControlStateNormal];
    quitBtn.frame = CGRectMake(25, self.view.height/2.5, App_Frame_Width-50, 44);
    [quitBtn applyActionStyle];
    [quitBtn addTarget:self action:@selector(quitLogin:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:quitBtn];
    
    // Do any additional setup after loading the view.
}

- (UIButton *)actionButton:(NSString *)str
{
    UIButton *button = [[UIButton alloc]init];
    button.frame = CGRectMake(0, 20, App_Frame_Width, 44);
    button.backgroundColor = [UIColor whiteColor];
    
    UIView *topView = [[UIView alloc]init];
    topView.backgroundColor = RGBACOLOR(226, 226, 226, 1.0);
    topView.frame = CGRectMake(0, 0, App_Frame_Width, 0.5);
    [button addSubview:topView];
    
    UIView *bottonView = [[UIView alloc]init];
    bottonView.backgroundColor = RGBACOLOR(226, 226, 226, 1.0);
    bottonView.frame = CGRectMake(0, 44, App_Frame_Width, 0.5);
    [button addSubview:bottonView];
    
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.frame = CGRectMake(15, 0, 100, 44);
    titleLabel.text = str;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont systemFontOfSize:14];
    [button addSubview:titleLabel];
    
    UIImage *image = [UIImage imageNamed:@"next"];
    UIButton *nextBtn = [[UIButton alloc]init];
    nextBtn.frame = CGRectMake(App_Frame_Width-50, 0, 44, 44);
    [nextBtn setImage:image forState:UIControlStateNormal];
    nextBtn.userInteractionEnabled = NO;
    [button addSubview:nextBtn];
    
    [button setBackgroundImage:[Utils createImageWithColor:RGBACOLOR(226, 226, 226, 1.0)] forState:UIControlStateHighlighted];
    return button;
}

- (IBAction)modifyPassCode:(id)sender
{
    SLModfiyPassCodeViewController *vc = [[SLModfiyPassCodeViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)openAbout:(id)sender
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    SLAboutViewController *vc = [sb instantiateViewControllerWithIdentifier:@"SLAboutViewController"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)quitLogin:(id)sender
{
    UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:@"" message:@"是否确定退出当前账号？"delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"退出登录", nil];
    [alterView show];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 1){
        [[UserModel sharedInstance] clean];
        [SLDBManager deleteUserAccount];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
